import os
from pathlib import Path

# 基础路径配置
BASE_DIR = Path(__file__).resolve().parent.parent
UPLOAD_DIR = os.path.join(BASE_DIR, 'upload')

# 上传目录配置
EXTRACT_DIR = os.path.join(UPLOAD_DIR, 'extracted')
OUTPUT_DIR = os.path.join(UPLOAD_DIR, 'output')
OCR_DIR = os.path.join(UPLOAD_DIR, 'ocr')
OCR_IMG_DIR = os.path.join(OCR_DIR, 'img')
OCR_TEXT_DIR = os.path.join(OCR_DIR, 'text')

# 文件大小限制（100MB）
MAX_FILE_SIZE = 100 * 1024 * 1024

# 允许的文件类型
ALLOWED_EXTENSIONS = {
    'zip': 'application/zip',
    'pdf': 'application/pdf'
}

# OCR配置
OCR_LANG = 'chi_sim+eng'
OCR_CONFIG = '--oem 1 --psm 3'

# 日志配置
LOG_DIR = os.path.join(BASE_DIR, 'logs')
LOG_FILE = os.path.join(LOG_DIR, 'app.log')

# 确保所有必要的目录存在
def ensure_directories():
    directories = [
        UPLOAD_DIR,
        EXTRACT_DIR,
        OUTPUT_DIR,
        OCR_DIR,
        OCR_IMG_DIR,
        OCR_TEXT_DIR,
        LOG_DIR
    ]
    
    for directory in directories:
        os.makedirs(directory, exist_ok=True)
        os.chmod(directory, 0o755)

# 初始化时创建目录
ensure_directories() 